from myelin.server.nodetype.Events import EventHandler
from myelin.server.nodetype.Document import Document

from Ft.Rdf.Parsers.Versa.Serializers.Vrj import Serializer

from nodetypes import config

class Document(Document):
    
    method = 'vrj'
    imt = config.METHODS_TO_IMT['vrj']
    
    newSerializer = Serializer
    
    def createDocument(self, context, source):
        
        s = self.newSerializer(
            context.event.data.results
        )
        
        doc, imt = s.serialize(
            None,
            context.namespaceMaps,
            context.preferredEncoding
        )
        
        if isinstance(doc,str):
            return doc, self.getImt(
                context,
                s.method,
                imt,
                context.preferredEncoding
            )
        else:
            return doc, self.getImt(
                context,
                s.method,
                imt
            )
       

class EventHandler(EventHandler):

    newDocument = Document
    
# cleanup
del Serializer, \
    config